<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tk_CreateSelHandler manual page - Tk Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tk C API</a> <small>&gt;</small> CrtSelHdlr</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<H3><A NAME="M2">NAME</A></H3>
Tk_CreateSelHandler, Tk_DeleteSelHandler &mdash; arrange to handle requests for a selection
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tk.h&gt;</B><BR>
<B>Tk_CreateSelHandler</B>(<I>tkwin, selection, target, proc, clientData, format</I>)<BR>
<B>Tk_DeleteSelHandler</B>(<I>tkwin, selection, target</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT><A HREF="../TkLib/WindowId.htm">Tk_Window</A> <B>tkwin</B> (in)<DD>
Window for which <I>proc</I> will provide selection information.
<P><DT>Atom <B><A HREF="../TkCmd/selection.htm">selection</A></B> (in)<DD>
The name of the selection for which <I>proc</I> will provide
selection information.
<P><DT>Atom <B>target</B> (in)<DD>
Form in which <I>proc</I> can provide the selection (e.g. STRING
or FILE_NAME).  Corresponds to <I>type</I> arguments in <B><A HREF="../TkCmd/selection.htm">selection</A></B>
commands.
<P><DT>Tk_SelectionProc <B>*proc</B> (in)<DD>
Procedure to invoke whenever the selection is owned by <I>tkwin</I>
and the selection contents are requested in the format given by
<I>target</I>.
<P><DT>ClientData <B>clientData</B> (in)<DD>
Arbitrary one-word value to pass to <I>proc</I>.
<P><DT>Atom <B><A HREF="../TclCmd/format.htm">format</A></B> (in)<DD>
If the selection requestor is not in this process, <I>format</I> determines
the representation used to transmit the selection to its
requestor.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
<B>Tk_CreateSelHandler</B> arranges for a particular procedure
(<I>proc</I>) to be called whenever <I>selection</I> is owned by
<I>tkwin</I> and the selection contents are requested in the
form given by <I>target</I>.
<I>Target</I> should be one of
the entries defined in the left column of Table 2 of the
X Inter-Client Communication Conventions Manual (ICCCM) or
any other form in which an application is willing to present
the selection.  The most common form is STRING.
<P>
<I>Proc</I> should have arguments and result that match the
type <B>Tk_SelectionProc</B>:
<PRE>typedef int <B>Tk_SelectionProc</B>(
        ClientData <I>clientData</I>,
        int <I>offset</I>,
        char *<I>buffer</I>,
        int <I>maxBytes</I>);</PRE>
The <I>clientData</I> parameter to <I>proc</I> is a copy of the
<I>clientData</I> argument given to <B>Tk_CreateSelHandler</B>.
Typically, <I>clientData</I> points to a data
structure containing application-specific information that is
needed to retrieve the selection.  <I>Offset</I> specifies an
offset position into the selection, <I>buffer</I> specifies a
location at which to copy information about the selection, and
<I>maxBytes</I> specifies the amount of space available at
<I>buffer</I>.  <I>Proc</I> should place a NULL-terminated string
at <I>buffer</I> containing <I>maxBytes</I> or fewer characters
(not including the terminating NULL), and it should return a
count of the number of non-NULL characters stored at
<I>buffer</I>.  If the selection no longer exists (e.g. it once
existed but the user deleted the range of characters containing
it), then <I>proc</I> should return -1.
<P>
When transferring large selections, Tk will break them up into
smaller pieces (typically a few thousand bytes each) for more
efficient transmission.  It will do this by calling <I>proc</I>
one or more times, using successively higher values of <I>offset</I>
to retrieve successive portions of the selection.  If <I>proc</I>
returns a count less than <I>maxBytes</I> it means that the entire
remainder of the selection has been returned.  If <I>proc</I>'s return
value is <I>maxBytes</I> it means there may be additional information
in the selection, so Tk must make another call to <I>proc</I> to
retrieve the next portion.
<P>
<I>Proc</I> always returns selection information in the form of a
character string.  However, the ICCCM allows for information to
be transmitted from the selection owner to the selection requestor
in any of several formats, such as a string, an array of atoms, an
array of integers, etc.  The <I>format</I> argument to
<B>Tk_CreateSelHandler</B> indicates what format should be used to
transmit the selection to its requestor (see the middle column of
Table 2 of the ICCCM for examples).  If <I>format</I> is not
STRING, then Tk will take the value returned by <I>proc</I> and divided
it into fields separated by white space.  If <I>format</I> is ATOM,
then Tk will return the selection as an array of atoms, with each
field in <I>proc</I>'s result treated as the name of one atom.  For
any other value of <I>format</I>, Tk will return the selection as an
array of 32-bit values where each field of <I>proc</I>'s result is
treated as a number and translated to a 32-bit value.  In any event,
the <I>format</I> atom is returned to the selection requestor along
with the contents of the selection.
<P>
If <B>Tk_CreateSelHandler</B> is called when there already exists a
handler for <I>selection</I> and <I>target</I> on <I>tkwin</I>, then the
existing handler is replaced with a new one.
<P>
<B>Tk_DeleteSelHandler</B> removes the handler given by <I>tkwin</I>,
<I>selection</I>, and <I>target</I>, if such a handler exists.
If there is no such handler then it has no effect.
<H3><A NAME="M6">KEYWORDS</A></H3>
<A href="../Keywords/F.htm#format">format</A>, <A href="../Keywords/H.htm#handler">handler</A>, <A href="../Keywords/S.htm#selection">selection</A>, <A href="../Keywords/T.htm#target">target</A>
<div class="copy">Copyright &copy; 1990-1994 The Regents of the University of California.
<BR>Copyright &copy; 1994-1996 Sun Microsystems, Inc.
</div>
</BODY></HTML>
